<?php 
/**
 * 商品列表控制器
 */
class GoodListController extends AuthController{
    /**
     * 
     */
    private $model;
     
	public function __auto(){
	    $this->model = K('GoodList');
	}
	
    public function index(){
    	$gid = Q('get.gid',0,'intval');
    	if(IS_POST){
	    	if(!$this->model->addData()){
	    		$this->error($this->model->error);
	    	}
			$this->success('添加成功');
	    }
		//顶部标题和底下下拉框数据
		$addData = M()->join('__goods_attr__ ga JOIN __attribute__ ta ON ga.attribute_atid=ta.atid')->where("goods_gid={$gid} AND at_type=1")->group('at_value')->order('gtid ASC')->all();
		foreach ($addData as $k => $v) {
			$addData[$k]['value'] = K('Goods_Attr')->where("goods_gid={$gid} AND attribute_atid={$v['atid']}")->all();
		}
		$this->assign('addData',$addData);
		
		//显示当前商品的货品列表数据
		$showData = K('GoodList')->where("goods_gid={$gid}")->all();	
		foreach ($showData as $k => $v) {
			$showData[$k]['value'] = K('Goods_Attr')->where("gtid in({$v['combine']})")->all();
		}
		$this->assign('showData',$showData);

        $this->display(); 
    }
	
	public function edit(){
		$gid = Q('get.gid',0,'intval');
		$glid = Q('get.glid',0,'intval');
		if(IS_POST){
			if(!$this->model->editData($glid)){
				$this->error($this->model->error);
			}
			$this->success('修改成功',U('index',array('gid'=>$gid)));
		}
		
		//获得旧数据
		$oldData = $this->model->where("glid={$glid}")->find();
		$oldData['combine']=explode(',', $oldData['combine']);
		$this->assign('oldData',$oldData);
		
		//顶部标题和底下下拉框数据
		$addData = M()->join('__goods_attr__ ga JOIN __attribute__ ta ON ga.attribute_atid=ta.atid')->where("goods_gid={$gid} AND at_type=1")->group('at_value')->order('gtid ASC')->all();
		foreach ($addData as $k => $v) {
			$addData[$k]['value'] = K('Goods_Attr')->where("goods_gid={$gid} AND attribute_atid={$v['atid']}")->all();
		}
		$this->assign('addData',$addData);
		
	    $this->display();
	}
	
	
	/**
	 * 删除
	 */
	public function del(){
	    $glid = Q('get.glid',0,'intval');
		//删除分类
		$this->model->where("glid={$glid}")->delete();
		//1.提示信息 2.跳转地址 3.跳转时间
		$this->success('删除成功');
	}
	
	
	
	
	
	
	
 }
 
 
 
 
 
 
 
 
 
 
 




 ?>